package org.example.ychdp.Config;

import org.example.ychdp.interceptor.loginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private loginInterceptor loginInterceptor;
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/toLoginPage").setViewName("redirect:toLogin");
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login")
                .excludePathPatterns("/captcha")
                .excludePathPatterns("/hello")
                .excludePathPatterns("/index")
                .excludePathPatterns("/admin")
                .excludePathPatterns("/register")
                .excludePathPatterns("/admin/helloAdmin")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/css/**")   // 排除CSS静态资源
                .excludePathPatterns("/js/**")    // 排除JS静态资源
                .excludePathPatterns("/img/**")   // 排除图片资源
                .excludePathPatterns("/fonts/**") // 排除字体资源
                .excludePathPatterns("/static/**"); // 如果静态资源路径前带 /static;

    }
}
